/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author has
 */
@Entity
@Table(name = "barang", catalog = "onsale", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Barang.findAll", query = "SELECT b FROM Barang b"),
    @NamedQuery(name = "Barang.findByIdBarang", query = "SELECT b FROM Barang b WHERE b.idBarang = :idBarang"),
    @NamedQuery(name = "Barang.findByNamaBarang", query = "SELECT b FROM Barang b WHERE b.namaBarang = :namaBarang"),
    @NamedQuery(name = "Barang.findByKategoriBarang", query = "SELECT b FROM Barang b WHERE b.kategoriBarang = :kategoriBarang"),
    @NamedQuery(name = "Barang.findByReviewBarang", query = "SELECT b FROM Barang b WHERE b.reviewBarang = :reviewBarang"),
    @NamedQuery(name = "Barang.findByFotoBarang", query = "SELECT b FROM Barang b WHERE b.fotoBarang = :fotoBarang")})
public class Barang implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idBarang", nullable = false)
    private Integer idBarang;
    @Column(name = "namaBarang", length = 25)
    private String namaBarang;
    @Column(name = "kategoriBarang", length = 25)
    private String kategoriBarang;
    @Column(name = "reviewBarang", length = 1000)
    private String reviewBarang;
    @Column(name = "fotoBarang", length = 200)
    private String fotoBarang;
    @JoinColumn(name = "idUser", referencedColumnName = "idUser", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private User idUser;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idBarang", fetch = FetchType.LAZY)
    private Collection<Komentarbarang> komentarbarangCollection;

    public Barang() {
    }

    public Barang(Integer idBarang) {
        this.idBarang = idBarang;
    }

    public Integer getIdBarang() {
        return idBarang;
    }

    public void setIdBarang(Integer idBarang) {
        this.idBarang = idBarang;
    }

    public String getNamaBarang() {
        return namaBarang;
    }

    public void setNamaBarang(String namaBarang) {
        this.namaBarang = namaBarang;
    }

    public String getKategoriBarang() {
        return kategoriBarang;
    }

    public void setKategoriBarang(String kategoriBarang) {
        this.kategoriBarang = kategoriBarang;
    }

    public String getReviewBarang() {
        return reviewBarang;
    }

    public void setReviewBarang(String reviewBarang) {
        this.reviewBarang = reviewBarang;
    }

    public String getFotoBarang() {
        return fotoBarang;
    }

    public void setFotoBarang(String fotoBarang) {
        this.fotoBarang = fotoBarang;
    }

    public User getIdUser() {
        return idUser;
    }

    public void setIdUser(User idUser) {
        this.idUser = idUser;
    }

    @XmlTransient
    public Collection<Komentarbarang> getKomentarbarangCollection() {
        return komentarbarangCollection;
    }

    public void setKomentarbarangCollection(Collection<Komentarbarang> komentarbarangCollection) {
        this.komentarbarangCollection = komentarbarangCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idBarang != null ? idBarang.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Barang)) {
            return false;
        }
        Barang other = (Barang) object;
        if ((this.idBarang == null && other.idBarang != null) || (this.idBarang != null && !this.idBarang.equals(other.idBarang))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Barang[ idBarang=" + idBarang + " ]";
    }
    
}
